message(NOTICE "开始构建 mp3lame 模块")
# 检查构建目标是否存在
if(TARGET mp3lame-${MP3LAME_TAG})
    message(NOTICE "mp3lame 模块已存在 mp3lame-${MP3LAME_TAG}")
 return()
endif()
# 检查安装文件是否存在
existsInstallFiles(
    ${MODULE_STAMP}/mp3lame/${MP3LAME_TAG}
    ${MODULE_INSTALL_DIR}/mp3lame/${MP3LAME_TAG}
    mp3lame-${MP3LAME_TAG})
# 配置库参数成成规则
set(MP3LAME_CONFIGURE CACHE STRING "mp3lame configure" FORCE)
if(BUILD_SHARED_LIBS)
    list(APPEND MP3LAME_CONFIGURE "--enable-shared")
else()
    list(APPEND MP3LAME_CONFIGURE "--disable-shared")
endif()
if(BUILD_STATIC_LIBS)
    list(APPEND MP3LAME_CONFIGURE "--enable-static")
else()
    list(APPEND MP3LAME_CONFIGURE "--disable-static")
endif()
# Android 配置 模块
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
    # 编译器工具链
    list(APPEND MP3LAME_CONFIGURE "--host=${TARGET_ABI}")
    list(APPEND MP3LAME_CONFIGURE "--with-sysroot=${CMAKE_SYSROOT}")
    list(APPEND MP3LAME_CONFIGURE "CC=${CMAKE_C_COMPILER}")
    list(APPEND MP3LAME_CONFIGURE "CXX=${CMAKE_CXX_COMPILER}")
    list(APPEND MP3LAME_CONFIGURE "STRIP=${STRIP}")
    list(APPEND MP3LAME_CONFIGURE "AR=${AR}")
    list(APPEND MP3LAME_CONFIGURE "RANLIB=${RANLIB}")
    list(APPEND MP3LAME_CONFIGURE "CFLAGS=${CMAKE_C_FLAGS}")
    list(APPEND MP3LAME_CONFIGURE "LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}")

endif()


# 构建 mp3lame 库
ExternalProject_Add(
    mp3lame-${MP3LAME_TAG}
    # 目录配置
    PREFIX         ${EXTERNAL_PROJECT_ROOT}                    # ✅ 显式设置 prefix 目录
    SOURCE_DIR     ${MODULE_SRC}/mp3lame/${MP3LAME_TAG}          # ✅ 显式设置 source 目录
    BINARY_DIR     ${MODULE_BUILD}/mp3lame/${MP3LAME_TAG}        # ✅ 显式设置 build 目录
    INSTALL_DIR    ${MODULE_INSTALL_DIR}/mp3lame/${MP3LAME_TAG}  # ✅ 显式设置 install 目录
    STAMP_DIR      ${MODULE_STAMP}/mp3lame/${MP3LAME_TAG}        # ✅ 显式设置 stamp 目录
    TMP_DIR        ${MODULE_TMP}/mp3lame/${MP3LAME_TAG}          # ✅ 显式设置 tmp 目录

    DOWNLOAD_COMMAND # 下载命令
        COMMAND ${CMAKE_COMMAND}
            -DSOURCE_DIR=<SOURCE_DIR>
            -DGIT_REPOSITORY=${MP3LAME_REPO}
            -DGIT_TAG=${MP3LAME_TAG}
            -P ${__DIR}/utils/git.cmake

    CONFIGURE_COMMAND
        <SOURCE_DIR>/configure
            --prefix=<INSTALL_DIR>
            --disable-gtktest
            --disable-analyzer-hooks
            --disable-mp3x
            --disable-mp3rtp
            --enable-dynamic-frontends
            --enable-expopt=yes
            --disable-debug
            --disable-frontend
            ${MP3LAME_CONFIGURE}

    # 构建命令
    BUILD_COMMAND     make -j${NPROC}
    # 安装命令
    INSTALL_COMMAND
        COMMAND make install
            # 将安装文件路径保存到 文件去
            COMMAND ${CMAKE_COMMAND}
            -DINSTALL_DIR=<INSTALL_DIR>
            -DCMAKE_PREFIX_PATH=${SYSTEM_PREFIX}
            -P ${__DIR}/utils/write_install_files.cmake
    # ✅ 启用所有日志（调试必备）
    LOG_DOWNLOAD      OFF                           # 下载日志
    LOG_CONFIGURE     OFF                            # 配置日志
    LOG_BUILD         OFF                           # 构建日志
    LOG_INSTALL       OFF                           # 安装日志
    LOG_OUTPUT_ON_FAILURE ON                       # 失败时自动输出日志
   # DEPENDS mp3lame-${MP3LAME_TAG}-configure
    STEP_TARGETS configure build install # 关键：添加 install 步骤
)

add_library(mp3lame::mp3lame STATIC IMPORTED)
# 属性配置
set_target_properties(mp3lame::mp3lame PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
    IMPORTED_LOCATION ${MODULE_INSTALL_DIR}/mp3lame/${MP3LAME_TAG}/lib/libmp3lame.a
    INTERFACE_INCLUDE_DIRECTORIES ${MODULE_INSTALL_DIR}/mp3lame/${MP3LAME_TAG}/include
)
# 依赖库
add_dependencies(mp3lame::mp3lame mp3lame-${MP3LAME_TAG})







